{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%classpath add mvn\n",
    "org.apache.spark spark-hive_2.11 2.4.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%spark\n",
    "SparkSession\n",
    "  .builder()\n",
    "  .master(\"local[4]\")\n",
    "  .appName(\"Spark Hive Example\")\n",
    "//.config(\"spark.sql.catalogImplementation\",\"hive\")\n",
    ".enableHiveSupport()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import java.io.File\n",
    "\n",
    "import org.apache.spark.sql.{Row, SaveMode, SparkSession}\n",
    "\n",
    "case class Record(key: Int, value: String)\n",
    "\n",
    "import spark.implicits._\n",
    "import spark.sql\n",
    "\n",
    "val kv1File = new File(\"../resources/data/kv1.txt\").getCanonicalPath\n",
    "\n",
    "sql(\"CREATE TABLE IF NOT EXISTS src (key INT, value STRING) USING hive\")\n",
    "sql(\"LOAD DATA LOCAL INPATH '\"+kv1File+\"' INTO TABLE src\")\n",
    "\n",
    "// Queries are expressed in HiveQL\n",
    "sql(\"SELECT * FROM src\").show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Scala",
   "language": "scala",
   "name": "scala"
  },
  "language_info": {
   "codemirror_mode": "text/x-scala",
   "file_extension": ".scala",
   "mimetype": "",
   "name": "Scala",
   "nbconverter_exporter": "",
   "version": "2.11.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": false,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": false,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
